//This is AmiCo library. It connects Java-class with Python-module.
#include <Python.h>
#include <jni.h>
#include "JavaCallsPython.h"
#include <iostream>

JNIEXPORT jint JNICALL
Java_JavaCallsPython_mean (JNIEnv *env, jobject obj, jint a, jint b)
{
        Py_Initialize();//
	std::cout << "\nC++: !Loading python stuff: \n";
	//Importing needed module
	PyObject* main_module = PyImport_ImportModule("JavaCallsPython");
	//Checking if the module has been successfully imported
	if (main_module == 0)
	{
		std::cout << "\nC++: Python module had not been loaded\n";
		PyErr_Print();
	}
	else
        	std::cout << "\nC++: Python module has been loaded SUCCESSFULY\n";
	//Calling our function from Python-module
	PyObject* res = PyObject_CallMethod(main_module, "computeMean", "(ii)", a, b);
	//Converting res to a C-type
	long result = PyInt_AsLong(res) ;
	//Printing our result
	std::cout << "\n C++: result = " << result << "\n";
//	Py_Finalize();
	return result;
}
